package com.matrix.java.chap_06;

public class Ex6_22 {
    public static void main(String[] args) {
        System.out.println(Math.sqrt(34543));
        System.out.println();
        System.out.println(sqrt(34543));
    }

    private static double sqrt(long n) {
        double nextGuess = 1;
        double lastGuess;
        do {
            lastGuess = nextGuess;
            nextGuess = (lastGuess + n / lastGuess) / 2;
        } while (Math.abs(lastGuess - nextGuess) > 0.0001);
        return nextGuess;
    }
}
